# Maintainer: Chocobo1

_realname=zstd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.2
pkgrel=1
pkgdesc="Zstandard - Fast real-time compression algorithm (mingw-w64)"
arch=('any')
url='https://facebook.github.io/zstd/'
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/facebook/${_realname}/archive/v${pkgver}.tar.gz"
        "makefile-install.patch"
        "pzstd-c++11.patch")
sha256sums=('980b8febb0118e22f6ed70d23b5b3e600995dbf7489c1f6d6122c1411cdda8d8'
            'b80af0d89a51555e96281446fa7c5ae1ee2543a001fa6ec140a41f93c4c8e1e0'
            '34c2872388f04a835dbf99db8c6c945d2f451470703b9f66e4c718dcf84373cf')


prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/makefile-install.patch"
  patch -p1 -i "${srcdir}/pzstd-c++11.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make clean && make
  make -C contrib/pzstd clean && make -C contrib/pzstd
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  make DESTDIR="${pkgdir}" PREFIX="${MINGW_PREFIX}" install
  install -D -m755 "contrib/pzstd/pzstd" "${pkgdir}${MINGW_PREFIX}/bin/pzstd"

  install -D -m644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -D -m644 "PATENTS" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/PATENTS"
}
